Paillier Encrypted Linear Classification Example

DISCLAIMER: This is a proof-of-concept implementation. It does not represent a remotely product ready implementation or follow proper conventions for security, convenience, or scalability. It is part of a broader proof-of-concept demonstrating the vision of the OpenMined project, its major moving parts, and how they might work together.

NOTE: One needs capusle to establish a client for decryption and re-encryption of weights.


In [ ]:
from syft.he.paillier import KeyPair
from syft.nn.linear import LinearClassifier
import numpy as np

from capsule.django_client import LocalDjangoCapsuleClient

In [ ]:
capsule = LocalDjangoCapsuleClient()
model = LinearClassifier(n_inputs=4, n_labels=2, capsule_client=capsule)
epochs = 3

In [ ]:
model = model.encrypt()

In [ ]:
input = np.array([[0,0,1,1],[0,0,1,0],[1,0,1,1],[0,0,1,0]])
target = np.array([[0,1],[0,0],[1,1],[0,0]])

In [ ]:
for i in range(epochs):
    model.learn(input, target, alpha=0.5)

In [ ]:
model = model.decrypt()

In [ ]:
for value in input:
    print(model.forward(value))